/**
 * 1
 *  
 * @Author : roryrywang
 * @DateTime : 24-9-7 下午3:55
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int getNum(int x) {
    int ans = 0;
    while (x) {
        int mod = x % 10;
        if (mod == 4 || mod == 6)ans++;
        x /= 10;
    }
    return ans;
}

int main() {
    int n, m;
    cin >> n >> m;
    int maxNum = -1;
    int res = 0;
    for (int i = n; i <= m; ++i) {
        int tmp = getNum(i);
        if (tmp >= maxNum) {
            maxNum = tmp;
            res = i;
        }
    }
    cout << res;
    return 0;
}